package com.mo.controller;

import com.github.pagehelper.PageInfo;
import com.mo.model.TActivityRemark;
import com.mo.query.ActivityRemarkQuery;
import com.mo.result.R;
import com.mo.service.ActivityRemarkService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author mo
 * version
 */
@RestController
public class ActivityRemarkController {

    @Resource
    private ActivityRemarkService activityRemarkService;


    @PostMapping("/api/activity/remark")
    //前端用对象形式传，这里变成json数据格式要用@RequestBody来接受，转成java对象
    public R addActivityRemark(@RequestBody ActivityRemarkQuery activityRemarkQuery){
        int save=activityRemarkService.saveActivityRemark(activityRemarkQuery);
        return save>=1?R.OK():R.FAIL();

    }
    @GetMapping("/api/activity/remark")
    public R activityRemarkPage(@RequestParam(value = "current", required = false) Integer current,
                                @RequestParam(value = "activityId") Integer activityId){
        ActivityRemarkQuery activityRemarkQuery = new ActivityRemarkQuery();
        activityRemarkQuery.setActivityId(activityId);
        if (current==null){
            current=1;
        }
        PageInfo<TActivityRemark> pageInfo = activityRemarkService.getActivityRemarkByPage(current,activityRemarkQuery);
        return R.OK(pageInfo);
    }

    @GetMapping("/api/activity/remark/{id}")
    public R activityRemarkEdit(@PathVariable Integer id){
        TActivityRemark activityRemark= activityRemarkService.getActivityRemarkById(id);
        return R.OK(activityRemark);
    }

    @PutMapping("/api/activity/remark/edit")
    //前端用对象形式传，这里变成json数据格式要用@RequestBody来接受，转成java对象
    public R editActivityRemark(@RequestBody ActivityRemarkQuery activityRemarkQuery){
        int update=activityRemarkService.updateActivityRemark(activityRemarkQuery);
        return update>=1?R.OK():R.FAIL();
    }

    @DeleteMapping(value = "/api/activity/remark/{id}")
    public R delActivityRemark(@PathVariable(value = "id") Integer id){
        int del=activityRemarkService.delActivityRemarkById(id);
        return del>=1?R.OK():R.FAIL();
    }
}
